package com.sinopec.handdevice.presenter

import com.sinopec.basemodule.api.BaseModuleApi
import com.sinopec.basemodule.http.CommonObserver
import com.sinopec.basemodule.http.ExceptionEngine
import com.sinopec.basemodule.model.StockOutListModel
import com.sinopec.handdevice.contract.StockOutListContract

/**
 * @author lwj
 * @ClassName: StockOutListPresenter
 * @Description: 出库-出库列表
 */
class StockOutListPresenter(view: StockOutListContract.View?) :
    StockOutListContract.Presenter(view!!) {

    override fun stockOutList(machineCode: String) {
        val resultObservable = BaseModuleApi.stockOutList(machineCode)
        toSubscribe(resultObservable, object : CommonObserver<List<StockOutListModel>>(mView.context) {
                override fun onNext(list: List<StockOutListModel>) {
                    mView.refreshUI(list)
                }

                override fun onError(t: ExceptionEngine.ResponseThrowable) {
                    mView.refreshUI(getData())
                    //mView.showMessage(t.message)
                }
            })
    }

    /**
     * @author lwj
     * @Description:测试数据
     */
    private fun getData(): List<StockOutListModel> {
        val list: MutableList<StockOutListModel> = ArrayList()
        for (i in 1..9) {
            val model = StockOutListModel()
            //交互标识
            model.outboundIntegrationId = "1000$i".toLong()
            //来源节点，库位
            model.fromLocationName = "库位" + 1
            //仓库名称
            model.warehouseName = "祥隆库" + 1
            //仓库编码
            model.warehouseCode = "C100$i"
            //目的节点-客户
            model.toCustomer = "石化客户$i"
            //车牌号
            model.vehiclePlateNo = "沪A12345"
            //发货时间
            model.shipmentTime = "2025-05-25 12:14:20"
            //销售订单号
            model.salesOrderNo = "XS-2025001$i"
            //预约提货单号
            model.appointmentPickNo = "YY-2025001$i"
            //企业
            model.enterpriseName = "镇海石化$i"
            //司机姓名
            model.driverName = "张三$i"
            //身份证号码
            model.driverIdCard = "310422199805255511"
            //预约提货时间
            model.appointmentPickTime = "2025-05-25 12:14:20"
            //售达方
            model.soldToParty = "上海乐橘科技$i"
            //送达方
            model.shipToParty = "镇海石化$i"
            //物料名称
            model.mtrName = "聚丙烯颗粒-01$i"

            if (i % 2 == 0) {
                //仓库类型（1平面库，2立体库）
                model.warehouseType = 2
            } else {
                //仓库类型（1平面库，2立体库）
                model.warehouseType = 1
            }

            //已读有效托盘code集合 ,ArrayList
            val palletCodes: ArrayList<String> = ArrayList()
            palletCodes.add("86 10 81 42 B0 5D")
            palletCodes.add("86 10 81 42 B0 5E")
            palletCodes.add("86 10 81 42 B0 5F")

//            for (j in 10..50) {
//                palletCodes.add("87 11 22 33 44 $j")
//            }
            model.palletCodes = palletCodes

            list.add(model)
        }
        return list
    }
}